<template>
  <NvConfigProvider :dict-request="dictRequest">
    <NConfigProvider
      :theme="isDark ? darkTheme : null"
      :locale="zhCN"
      :date-locale="dateZhCN"
    >
      <NMessageProvider>
        <slot />
      </NMessageProvider>
    </NConfigProvider>
  </NvConfigProvider>
</template>

<script setup lang="ts">
import { useDark } from '@vueuse/core'
import { darkTheme, dateZhCN, NConfigProvider, NMessageProvider, zhCN } from 'naive-ui'
import { NvConfigProvider } from 'nv-crud'

const isDark = useDark({
  storageKey: 'vitepress-theme-appearance',
})

async function dictRequest(url: string) {
  return (await fetch(url)).json()
}
</script>
